import Vue from 'vue'
import Router from 'vue-router'
import Home from '@/pages/home/Home'
import Login from '@/pages/login/index'


import NProgress from 'nprogress'
import 'nprogress/nprogress.css'

Vue.use(Router)
//设置初始值
NProgress.configure({minimum:0.3})
// ↓↓↓处理路径login页面路由  同时修改下面路由守卫↓↓↓
const router = new Router({
  // mode: 'history',//去掉#号
  routes: [
    {
      path: '/',
      redirect: '/transcripts/login'
    },
    {
      path: '/transcripts/login',
      name: 'Login',
      component: Login
    },
    {
      path: '/StuList',
      name: 'StuList',
      component: () => import("../pages/students/stulist")
    },
    {
      path: "/Upload",
      name: "Upload",
      component: () => import("@/pages/upload/index")
    },
    {
      path: '/Grade',
      name: 'Grade',
      component: () => import("../pages/grade/index")
    },
    {
      path: '/transcripts/unofficial',
      name: 'Scores',
      component: () => import("../pages/scores/index")
    },

    {
      path: '/Home',
      name: 'home',
      component: Home,
      redirect: "/Students",
      children:[
        {
          path: "/Students",
          name: "Students",
          component: () => import("@/pages/students/index")
        },
        {
          path: "/Table2",
          name: "Table2",
          component: () => import("@/components/home/Table2")
        },
        {
          path: "/Major",
          name: "Major",
          component: () => import("@/pages/major/index")
        },
        {
          path: "/Course",
          name: "Course",
          component: () => import("@/pages/course/index")
        },
        {
          path: "/MajorCourse",
          name: "MajorCourse",
          component: () => import("@/pages/majorCourse/index")
        },
        // {
        //   path: "/Upload",
        //   name: "Upload",
        //   component: () => import("@/pages/upload/index")
        // },
        {
          path: "/Base",
          name: "Base",
          component: () => import("@/pages/base/index")
        }
      ]
    },
    
  ]
})
//挂载路由守卫
router.beforeEach((to,from,next) => {
  NProgress.start();
  if (to.path === '/transcripts/login') return next();
  // 取出token
  const token = window.sessionStorage.getItem('token');

  if (!token) return next('/transcripts/login');

  next();
})
//路由进入后  关闭进度
router.afterEach(()=>{
  NProgress.done()
})

export default router



